package com.example.victory.service;

import com.alibaba.fastjson.JSONObject;
import com.example.victory.swagger.handler.AppCustomerOverallServiceApiDelegate;
import com.example.victory.swagger.model.*;
import com.example.victory.utils.JsonUtils;
import com.cgws.fintech.sdk.api.inner.crmapi.model.ApiRequesFsdp;
import com.cgws.fintech.sdk.api.inner.crmapi.model.ApiRequesFsdpData;
import com.cgws.fintech.sdk.api.inner.crmapi.model.ApiResponseFsdp;
import com.example.victory.common.web.ServiceHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class AppCustomerOverAllService implements AppCustomerOverallServiceApiDelegate {

    @Autowired
    private  InnerOverAllServiceFsdpService innerOverAllServiceFsdpService;

    private String getCustomerId(ApiRequestCustomerId param){
        ServiceHelper.checkDataNotNull(param.getData(),"param.data");
        ServiceHelper.checkDataNotNull(param.getData().getCustomerId(),"param.data.customerId");
        return  param.getData().getCustomerId();
    }
    private void getCustomerServicePage( ApiRequestOverAllServicePage param){
        ServiceHelper.checkDataNotNull(param.getData(),"param.data");
        ServiceHelper.checkDataNotNull(param.getData().getCustomerId(),"param.data.customerId");
        ServiceHelper.checkDataNotNull(param.getData().getIndex(),"param.data.index");
        ServiceHelper.checkDataNotNull(param.getData().getPageSize(),"param.data.pageSize");
    }
    @Override
    public ResponseEntity<ApiResponseCustomerOverallService> getCustomerOverAllService(ApiRequestCustomerId param) {
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("customerId",getCustomerId(param));
        ResponseEntity<ApiResponseFsdp> fsdpResponseEntity= innerOverAllServiceFsdpService.getCustomerOverAllService(new ApiRequesFsdp().data(new ApiRequesFsdpData().params(jsonObject.toJSONString())));
        ApiResponseCustomerOverallServiceData service= JsonUtils.getResultEntity(fsdpResponseEntity,ApiResponseCustomerOverallServiceData.class);
        return ResponseEntity.ok(new ApiResponseCustomerOverallService().data(service));
    }

    @Override
    public ResponseEntity<ApiResponseCustomerOverallServiceEvent> getCustomerOverAllServiceEventPage(ApiRequestOverAllServicePage param) {
        getCustomerServicePage(param);
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("customerId",param.getData().getCustomerId());
        jsonObject.put("index",param.getData().getIndex());
        jsonObject.put("pageSize",param.getData().getPageSize());
        ResponseEntity<ApiResponseFsdp> fsdpResponseEntity= innerOverAllServiceFsdpService.getCustomerOverAllServiceEvent(new ApiRequesFsdp().data(new ApiRequesFsdpData().params(jsonObject.toJSONString())));
        ApiResponseCustomerOverallServiceEventData event= JsonUtils.getResultEntity(fsdpResponseEntity,ApiResponseCustomerOverallServiceEventData.class);
        return ResponseEntity.ok(new ApiResponseCustomerOverallServiceEvent().data(event));
    }

    @Override
    public ResponseEntity<ApiResponseCustomerOverallServiceProduct> getCustomerOverAllServiceProductPage(ApiRequestOverAllServicePage param) {
        getCustomerServicePage(param);
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("customerId",param.getData().getCustomerId());
        jsonObject.put("index",param.getData().getIndex());
        jsonObject.put("pageSize",param.getData().getPageSize());
        ResponseEntity<ApiResponseFsdp> fsdpResponseEntity= innerOverAllServiceFsdpService.getCustomerOverAllServiceProduct(new ApiRequesFsdp().data(new ApiRequesFsdpData().params(jsonObject.toJSONString())));
        ApiResponseCustomerOverallServiceProductData product= JsonUtils.getResultEntity(fsdpResponseEntity,ApiResponseCustomerOverallServiceProductData.class);
        return ResponseEntity.ok(new ApiResponseCustomerOverallServiceProduct().data(product));
    }

    @Override
    public ResponseEntity<ApiResponseCustomerOverallServiceRecord> getCustomerOverAllServiceRecordPage(ApiRequestOverAllServicePage param) {
        getCustomerServicePage(param);
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("customerId",param.getData().getCustomerId());
        jsonObject.put("index",param.getData().getIndex());
        jsonObject.put("pageSize",param.getData().getPageSize());
        ResponseEntity<ApiResponseFsdp> fsdpResponseEntity= innerOverAllServiceFsdpService.getCustomerOverAllServiceRecord(new ApiRequesFsdp().data(new ApiRequesFsdpData().params(jsonObject.toJSONString())));
        ApiResponseCustomerOverallServiceRecordData record= JsonUtils.getResultEntity(fsdpResponseEntity,ApiResponseCustomerOverallServiceRecordData.class);
        return ResponseEntity.ok(new ApiResponseCustomerOverallServiceRecord().data(record));
    }
}
